import { defineStore } from 'pinia'
import axios from 'axios'

export const useKnowledgeStore = defineStore('knowledge', {
  state: () => ({
    knowledgeList: [],
    currentKnowledge: null
  }),

  actions: {
    async getKnowledgeList() {
      const response = await axios.get('/api/knowledge/list')
      this.knowledgeList = response.data
      return response.data
    },

    async createKnowledge(data) {
      const response = await axios.post('/api/knowledge/create', data)
      return response.data
    },

    async deleteKnowledge(id) {
      const response = await axios.delete(`/api/knowledge/${id}`)
      return response.data
    },

    async getFileList({ knowledgeId, page, pageSize }) {
      const response = await axios.get('/api/knowledge/files', {
        params: { knowledgeId, page, pageSize }
      })
      return response.data
    },

    async deleteFile(fileId) {
      const response = await axios.delete(`/api/knowledge/file/${fileId}`)
      return response.data
    }
  }
})
